var tblCenter;
$(function () {
    tblCenter = $('#tbl-center').DataTable(buildCenterOptions());
    $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
        //当切换tab时，强制重新计算列宽
        $.fn.dataTable.tables({visible: true, api: true}).columns.adjust();
    });
    trCssEvent(tblCenter);
});

function buildCenterOptions() {
    var options = {
        "serverSide": true,
        "autoWidth": true,
        "bAutoWidth": false,
        "deferRender": true,
        "searching": false,
        "ordering": true,
        "processing": true,
        "scrollX": true,
        "language": {
            "url": "//cdn.datatables.net/plug-ins/1.10.12/i18n/Chinese.json"
        },
        "ajax": {
            "url": '/api/center',
            "type": 'get',
            "dataType": 'json',
            data: function (params) {
                params['cid'] = $("#center-id").val();
            }
        },
        "columns": [{
            "data": "center_name"
        }],
        columnDefs: [{
            "targets": 1,
            "data": "center_id",
            "render": function (data, type, row, meta, full) {
                return "<a  href='Students?centerId=" + data + "' target='_blank'> 查看中心的孩子  </a>"

            }
        }, {"orderable": false, "targets": [0, 1]}
        ],
        "dom": "<'row'<'col-xs-12't>>r<'row'<'col-xs-2 lstyle'l><'col-xs-3'i><'col-xs-6  fright'p>>"
    };
    return options;
}

function selectCenter() {
    $("#btn-search-center").attr("disabled", "disabled");
    tblCenter.ajax.reload(function () {
        $("#btn-search-center").removeAttr("disabled");
    });
}

